/**
 * 11. 盛最多水的容器
 * https://leetcode-cn.com/problems/container-with-most-water/
 */

/**
 * @param {number[]} walls
 * @return {number}
 */
function maxArea(walls) {
  let l = 0;
  let r = walls.length - 1;
  let max = 0;
  while (l < r) {
    const lHeight = walls[l];
    const rHeight = walls[r];
    const dis = r - l;
    let capacity;
    if (lHeight <= rHeight) {
      capacity = dis * lHeight;
      l += 1;
    } else {
      capacity = dis * rHeight;
      r -= 1;
    }
    if (capacity > max) {
      max = capacity;
    }
  }
  return max;
}

console.log(maxArea([1, 8, 6, 2, 5, 4, 8, 3, 7]) === 49);
console.log(maxArea([1, 1]) === 1);
console.log(maxArea([4, 3, 2, 1, 4]) === 16);
console.log(maxArea([1, 2, 1]) === 2);
